#pragma once
#include<iostream>
using namespace std;


template<class T>
class BinaryNode
{
public:
	BinaryNode(const T& val)
	{
		//this = new BinaryNode<T>(val);
	}
	/*BinaryNode<T>* BinaryCreate(T* arr,int n, int* pi)
	{
		if (arr[*pi] == 0 || *pi >= n)
		{
			return this;
		}
		
		this = new BinaryNode(arr[*pi]);
		(*pi) += 1;
		this->left = BinaryCreate(arr, n, pi);
		this->right = BinaryCreate(arr, n, pi);
	}*/
	BinaryNode<T>* BinaryCreate(T* arr, int n, int* pi)
	{
		if (arr[*pi] == 0 || *pi >= n)
		{
			pi += 1;
			return nullptr;
		}

		BinaryNode<T>* root = new BinaryNode<T>(arr[*pi]);
		(*pi) += 1;
		root->left = BinaryCreate(arr, n, pi);
		root->right = BinaryCreate(arr, n, pi);
		return root;
	}

	void BinaryTreePrevOrder()
	{
		if (this == nullptr)
		{
			return;
		}
		cout << this->val << " ";
		BinaryTreePrevOrder(this->left);
		BinaryTreePrevOrder(this->right);
	}
private:
	T val;
	BinaryNode<T>* left;
	BinaryNode<T>* right;
};

